<?php
defined('SYSPATH') or die('No direct script access.');

class Controller_Default extends Controller_Template
{
    public $template = 'templates/default';

    /**
     * Initialize properties before running the controller methods (actions),
     * so they are available to our action.
     */
    public function before()
    {
        // Run anything that need ot run before this.
        parent::before();
        $this->auto_render = ! $this->request->is_ajax();
        if($this->auto_render)
        {
            $categoryTable = new Model_Category();
            // Initialize empty values
            $this->template->title            = '';
            $this->template->meta_keywords    = '';
            $this->template->meta_description = '';
            $this->template->meta_copywrite   = '';
            $this->template->header           = View::factory('templates/header');
            $this->template->sidebar          = View::factory('templates/sidebar', array('categories' => $categoryTable->find_all()));
            $this->template->content          = '';
            $this->template->footer           = View::factory('templates/footer');
            $this->template->styles           = array();
            $this->template->scripts          = array();
        }
    }

    /**
     * Fill in default values for our properties before rendering the output.
     */
    public function after()
    {
        if($this->auto_render)
        {
            // Define defaults
            $styles = array(
              'externals/s3/css/calendar.css' => 'screen',
              'externals/highslide/highslide.min.css' => 'screen',
              'assets/css/styles_articles_tpl.css' => 'screen',
              'assets/css/styles.css' => 'screen',

            );
            $scripts = array(
                'externals/s3/js/calendar.packed.js',
                'externals/s3/js/widget.js',
                'externals/s3/js/cookie.js',
                'externals/s3/js/lang/ru.js',
                'externals/flowplayer/flowplayer-3.2.9.min.js',
                'externals/highslide/highslide.packed.js',
                'assets/js/jquery.min.js',
            );

            // Add defaults to template variables.
            $this->template->styles  = array_reverse(array_merge($this->template->styles, $styles));
            $this->template->scripts = array_reverse(array_merge($this->template->scripts, $scripts));
        }

        // Run anything that needs to run after this.
        parent::after();
    }
}